package com.evil.common.activiti.enums;

import com.evil.common.core.enums.RCodeEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 待办转交类型
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@AllArgsConstructor
public enum PendingDivertTypeEnum {

    /**
     * 待办转交类型，0: 全部成员, 1: 指定成员
     */
    ALL(0, "全部成员"),
    ASSIGN(1, "指定成员"),
    ;

    @Getter
    private final int id;
    @Getter
    private final String name;

    public static Optional<PendingDivertTypeEnum> findById(Integer id) {
        if (null == id) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.id == id).findFirst();
    }

    public static PendingDivertTypeEnum isExistById(Integer id) {
        return PendingDivertTypeEnum.findById(id).orElseThrow(() ->
                new BusinessException(RCodeEnum.ERROR_PARAMETER, "待办转交类型参数错误"));
    }
}
